-- 模块类
Module = Module or Class("Module")

---@diagnostic disable-next-line: duplicate-set-field
function Module:ctor(name)
    self.loader = Loader.new(name)
    self.name = name
end

function Module:Sprite(url)
    local spf = self.loader:loadSpriteFrame(url)
    local node = Node.new()
    local sp = node:addComponent(Sprite)
    sp.spriteFrame = spf
    return node
end

function Module:Icon(name)
    local spf = self.loader:loadIcon(name)
    local node = Node.new()
    local sp = node:addComponent(Sprite)
    sp.spriteFrame = spf
    return node
end

function Module:Panel(name)
    local spf = self.loader:loadPanel(name)
    local node = Node.new()
    local sp = node:addComponent(Sprite)
    sp.spriteFrame = spf
    return node
end
local function tryRequire(luaPath)
    local _path = string.gsub(luaPath, "%.", "/")
    local info = love.filesystem.getInfo(_path)
    if info then
        require(luaPath)
    else
        local luaInfo = love.filesystem.getInfo(_path..".lua")
        if luaInfo then
            require(luaPath)
        end
    end
end

function Module:requireScripts()
    local path = self.name..".scripts"
    tryRequire(path..".base")
    tryRequire(path..".data")

    tryRequire(path..".codeResources.codeImages.codeIcons")
    tryRequire(path..".shaders")

    tryRequire(path..".systems")
    tryRequire(path..".tools")
    tryRequire(path..".outlook")
    tryRequire(path..".start")
end